package com.fruit.utils;

import java.util.ArrayList;
import java.util.List;



import com.fruit.service.IPaymentService;
import com.fruit.web.bo.impl.Payment;
import com.fruit.web.constant.ManageBeanConstants;
import com.fruit.web.constant.SpringBeanConstants;
import com.fruit.web.vo.common.LocalBean;


public final class PaymentUtil {
	public PaymentUtil() {
	  }
	public static List<Payment> getPayments() {
		IPaymentService paymentService = (IPaymentService)SpringFacesUtil.getManagedBean(SpringBeanConstants.PAYMENT_SERVICE_BEAN_NAME);
		paymentService.setEntityClass(Payment.class);
		paymentService.setPKClass(Long.class);
		LocalBean localBean = (LocalBean)SpringFacesUtil.getManagedBean(ManageBeanConstants.LOCAL_BEAN);
		List<Payment> payments = paymentService.findBy("paymentLocale", localBean.getLocale(),"serialNumber",true);
		return payments;
	}
	public static List<Payment> getPaymentsByPaymentTypeId(String paymentTypeId) {
		List<Payment> result = new ArrayList<Payment>();
		List<Payment> payments = getPayments();
		if (null == paymentTypeId || "".equals(paymentTypeId)) {
			result = payments;
		} else {
			if (null != payments && !(payments.isEmpty())) {
				for (Payment payment:payments) {
					if (paymentTypeId.equals(payment.getPaymentTypeId())) {
						result.add(payment);
					}
				}
			}
		}
		
		return result;
	}

}
